<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
  <head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
    <title></title>
    <link rel="stylesheet" type="text/css" href="../css/jsUnitStyle.css">
	<script language="JavaScript" type="text/javascript" src="../app/jsUnitCore.js"></script>
		
	<script language="JavaScript" type="text/javascript" src="../../../commonvalidate/front/commonvalidate_util.js"></script>
	<script language="JavaScript" type="text/javascript" src="../../../commonvalidate/front/commonvalidate_func.js"></script>
	<script language="JavaScript" type="text/javascript" src="../../../commonvalidate/front/commonvalidate_msg.js"></script>
	<script language="JavaScript" type="text/javascript" src="mock.js"></script>
	
<script language="JavaScript" type="text/javascript">

configure = new CommonValidateConfigure(validate_config);

function test_cv_checkIsNull() {
	
	test_context = { test:{value:null}};	
	var error_list = [];
	cv_checkIsNull("test", "advice_test", "TEST", null, error_list, configure);
	assertEquals(1, error_list.length);
	error = error_list[0];
	assertEquals("advice_test", error.advice_id);
	assertEquals("TEST不能为空。", error.error_msg);
	
	test_context = { test:{value:""}};
	error_list = [];
	cv_checkIsNull("test", "advice_test", "TEST", null, error_list, configure);
	assertEquals(1, error_list.length);
	error = error_list[0];
	assertEquals("advice_test", error.advice_id);
	assertEquals("TEST不能为空。", error.error_msg);
	
	test_context = { test:{value:"    "}};
	error_list = [];
	cv_checkIsNull("test", "advice_test", "TEST", null, error_list, configure);
	assertEquals(1, error_list.length);
	error = error_list[0];
	assertEquals("advice_test", error.advice_id);
	assertEquals("TEST不能为空。", error.error_msg);
}

function test_cv_checkLengthRange() {

	test_context = { test:{value:null}};	
	var error_list = [];
	cv_checkLengthRange("test", "advice_test", "TEST", [1, 20], error_list, configure);
	assertEquals(1, error_list.length);
	error = error_list[0];
	assertEquals("advice_test", error.advice_id);
	assertEquals("TEST的长度必须在1和20之间。", error.error_msg);
	
	test_context = { test:{value:"abcdefg"}};	
	var error_list = [];
	cv_checkLengthRange("test", "advice_test", "TEST", [1, 20], error_list, configure);
	assertEquals(0, error_list.length);	
	
	test_context = { test:{value:"ababababababababababab"}};	
	var error_list = [];
	cv_checkLengthRange("test", "advice_test", "TEST", [1, 20], error_list, configure);
	assertEquals(1, error_list.length);
	error = error_list[0];
	assertEquals("advice_test", error.advice_id);
	assertEquals("TEST的长度必须在1和20之间。", error.error_msg);
}

function test_cv_checkIsNumber() {
	
	test_context = { test:{value:null}};
	var error_list = [];
	cv_checkIsNumber("test", "advice_test", "TEST", null, error_list, configure);
	assertEquals(1, error_list.length);
	error = error_list[0];
	assertEquals("advice_test", error.advice_id);
	assertEquals("TEST不是有效的数字。", error.error_msg);
	
	test_context = { test:{value:"12ab"}};
	var error_list = [];
	cv_checkIsNumber("test", "advice_test", "TEST", null, error_list, configure);
	assertEquals(1, error_list.length);
	error = error_list[0];
	assertEquals("advice_test", error.advice_id);
	assertEquals("TEST不是有效的数字。", error.error_msg);
	
	test_context = { test:{value:"12"}};
	var error_list = [];
	cv_checkIsNumber("test", "advice_test", "TEST", null, error_list, configure);
	assertEquals(0, error_list.length);
	
	test_context = { test:{value:"12.12"}};
	var error_list = [];
	cv_checkIsNumber("test", "advice_test", "TEST", null, error_list, configure);
	assertEquals(0, error_list.length);
}

function test_cv_checkIsInt() {
	
	test_context = { test:{value:null}};
	var error_list = [];
	cv_checkIsInt("test", "advice_test", "TEST", null, error_list, configure);
	assertEquals(1, error_list.length);
	error = error_list[0];
	assertEquals("advice_test", error.advice_id);
	assertEquals("TEST必须是整数。", error.error_msg);
	
	test_context = { test:{value:"12.12"}};
	var error_list = [];
	cv_checkIsInt("test", "advice_test", "TEST", null, error_list, configure);
	assertEquals(1, error_list.length);
	error = error_list[0];
	assertEquals("advice_test", error.advice_id);
	assertEquals("TEST必须是整数。", error.error_msg);
	
	test_context = { test:{value:"12ab"}};
	var error_list = [];
	cv_checkIsInt("test", "advice_test", "TEST", null, error_list, configure);
	assertEquals(1, error_list.length);
	error = error_list[0];
	assertEquals("advice_test", error.advice_id);
	assertEquals("TEST必须是整数。", error.error_msg);
	
	test_context = { test:{value:"12"}};
	var error_list = [];
	cv_checkIsInt("test", "advice_test", "TEST", null, error_list, configure);
	assertEquals(0, error_list.length);
	
}

function test_cv_checkIsCheckBoxSelect() {
	
	test_context = { test: [{checked: false},{checked: false},{checked: false}]};
	var error_list = [];
	cv_checkIsCheckBoxSelect("test", "advice_test", "TEST", null, error_list, configure);
	assertEquals(1, error_list.length);
	error = error_list[0];
	assertEquals("advice_test", error.advice_id);
	assertEquals("请至少选择一个TEST", error.error_msg);
	
	test_context = { test: [{checked: false},{checked: true},{checked: false}]};
	var error_list = [];
	cv_checkIsCheckBoxSelect("test", "advice_test", "TEST", null, error_list, configure);
	assertEquals(0, error_list.length);	
}

function test_cv_checkSelectCheckBoxCount() {

	test_context = { test: [{checked: true},{checked: true},{checked: true}]};
	var error_list = [];
	cv_checkSelectCheckBoxCount("test", "advice_test", "TEST", [2], error_list, configure);
	assertEquals(1, error_list.length);
	error = error_list[0];
	assertEquals("advice_test", error.advice_id);
	assertEquals("最多只能选择2个TEST。", error.error_msg);
	
	test_context = { test: [{checked: true},{checked: false},{checked: true}]};
	var error_list = [];
	cv_checkSelectCheckBoxCount("test", "advice_test", "TEST", [2], error_list, configure);
	assertEquals(0, error_list.length);	
}

function test_cv_checkIsImg() {

	test_context = { test: {value:null}};
	var error_list = [];
	cv_checkIsImg("test", "advice_test", "TEST", null, error_list, configure);
	assertEquals(1, error_list.length);
	error = error_list[0];
	assertEquals("advice_test", error.advice_id);
	assertEquals("TEST不是正确的图片类型。", error.error_msg);
	
	test_context = { test: {value:"abc"}};
	var error_list = [];
	cv_checkIsImg("test", "advice_test", "TEST", null, error_list, configure);
	assertEquals(1, error_list.length);
	error = error_list[0];
	assertEquals("advice_test", error.advice_id);
	assertEquals("TEST不是正确的图片类型。", error.error_msg);
	
	test_context = { test: {value:"abc.txt"}};
	var error_list = [];
	cv_checkIsImg("test", "advice_test", "TEST", null, error_list, configure);
	assertEquals(1, error_list.length);
	error = error_list[0];
	assertEquals("advice_test", error.advice_id);
	assertEquals("TEST不是正确的图片类型。", error.error_msg);
	
	test_context = { test: {value:"abc.jpg"}};
	var error_list = [];
	cv_checkIsImg("test", "advice_test", "TEST", null, error_list, configure);
	assertEquals(0, error_list.length);
	
	
	test_context = { test: {value:"abc.jpppg"}};
	var error_list = [];
	cv_checkIsImg("test", "advice_test", "TEST", ["jpppg"], error_list, configure);
	assertEquals(0, error_list.length);
}

function test_cv_checkDateFormat() {
	
	test_context = { test: {value:null}};
	var error_list = [];
	cv_checkDateFormat("test", "advice_test", "TEST", ["yyyy-mm-dd"], error_list, configure);
	assertEquals(1, error_list.length);
	error = error_list[0];
	assertEquals("advice_test", error.advice_id);
	assertEquals("TEST的日期格式不正确。", error.error_msg);
	
	test_context = { test: {value:"2009-10-21"}};
	var error_list = [];
	cv_checkDateFormat("test", "advice_test", "TEST", ["yyyy-mm-dd"], error_list, configure);
	assertEquals(0, error_list.length);
	
	test_context = { test: {value:"2009-1-21"}};
	var error_list = [];
	cv_checkDateFormat("test", "advice_test", "TEST", ["yyyy-mm-dd"], error_list, configure);
	assertEquals(0, error_list.length);
	
	test_context = { test: {value:"2009-1-1"}};
	var error_list = [];
	cv_checkDateFormat("test", "advice_test", "TEST", ["yyyy-mm-dd"], error_list, configure);
	assertEquals(0, error_list.length);
	
	test_context = { test: {value:"2009/10/21"}};
	var error_list = [];
	cv_checkDateFormat("test", "advice_test", "TEST", ["yyyy-mm-dd"], error_list, configure);
	assertEquals(1, error_list.length);
	error = error_list[0];
	assertEquals("advice_test", error.advice_id);
	assertEquals("TEST的日期格式不正确。", error.error_msg);
	
	test_context = { test: {value:"2009-10-"}};
	var error_list = [];
	cv_checkDateFormat("test", "advice_test", "TEST", ["yyyy-mm-dd"], error_list, configure);
	assertEquals(1, error_list.length);
	error = error_list[0];
	assertEquals("advice_test", error.advice_id);
	assertEquals("TEST的日期格式不正确。", error.error_msg);
	
}

</script>
  </head>

  <body>
    <h1>CommonValidate function test.</h1>

    <p>This page contains tests for the JsUnit Assertion
    functions. To see them, take a look at the source.</p>
  </body>
</html>

